package com.zbkj.service.model.front.vo.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zbkj.dal.base.enums.FundDirectionEnums;
import com.zbkj.dal.base.enums.FundStatusEnums;
import com.zbkj.dal.base.enums.FundTradeTypeEnums;
import com.zbkj.dal.common.utils.MoneyUtil;
import com.zbkj.dal.entity.user.UserBalanceRecord;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;

@Data
@ApiModel
public class FundFlowVO {
    @ApiModelProperty("图片地址")
    private String image;

    @ApiModelProperty("流水类型")
    private String flowType;

    @ApiModelProperty("流水类型描述")
    private String flowTypeDesc;

    @ApiModelProperty("金额")
    private String amount;

    @ApiModelProperty("订单号")
    private String orderNo;

    @ApiModelProperty(value = "状态", example = "0")
    private String status;

    @ApiModelProperty(value = "状态描述", example = "冻结中")
    private String statusDesc;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("流水时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate flowTime;

    @ApiModelProperty("是否冻结")
    private Boolean frozen;

    public static FundFlowVO transform(UserBalanceRecord userBalanceRecord) {
        FundFlowVO fundFlowVO = new FundFlowVO();
        fundFlowVO.setImage(userBalanceRecord.getImage());
        fundFlowVO.setFlowType(userBalanceRecord.getLinkType());
        fundFlowVO.setFlowTypeDesc(FundTradeTypeEnums.getDescByCode(userBalanceRecord.getLinkType()));
        fundFlowVO.setAmount(String.format("%s￥%s", FundDirectionEnums.getSignalByCode(userBalanceRecord.getType()), MoneyUtil.prettyFormat(userBalanceRecord.getAmount())));
        fundFlowVO.setOrderNo(userBalanceRecord.getLinkId());
        fundFlowVO.setStatus(userBalanceRecord.getStatus());
        fundFlowVO.setStatusDesc(FundStatusEnums.getShowByCode(userBalanceRecord.getStatus()));
        fundFlowVO.setFlowTime(userBalanceRecord.getCreateTime().toLocalDate());
        fundFlowVO.setFrozen(StringUtils.equals(userBalanceRecord.getStatus(), FundStatusEnums.IN_TRANSIT.getCode()));
        fundFlowVO.setRemark(userBalanceRecord.getRemark());
        return fundFlowVO;
    }
}